local wanglu = fk.CreateSkill {

  name = "joy__wanglu",

  tags = { Skill.Compulsory, },

}



wanglu:addEffect(fk.EventPhaseStart, {
  name = "joy__wanglu",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(wanglu.name) and player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if table.find(player:getEquipments(Card.SubtypeWeapon), function(id) return Fk:getCardById(id).name == "joy__siege_engine" end) then
      player:gainAnExtraPhase(Player.Play)
    else
      local engine = table.find(U.prepareDeriveCards(room, wanglu_engine, "joy__wanglu_engine"), function (id)
        return room:getCardArea(id) == Card.Void
      end)
      if engine and U.canMoveCardIntoEquip(player, engine) then
        for i = 1, 3, 1 do
          room:setPlayerMark(player, "joy__xianzhu"..tostring(i), 0)
        end
        U.moveCardIntoEquip (room, player, engine, wanglu.name, true, player)
      end
    end
  end,
})

return wanglu